//
//  DiscoverViewController.m
//  CatSport
//
//  Created by yonghui liu on 2020/5/15.
//  Copyright © 2020 刘永慧. All rights reserved.
//

#import "DiscoverViewController.h"
#import "CommonDefine.h"
@interface DiscoverViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray1;
@property (nonatomic, strong) NSMutableArray *dataArray2;
@property (nonatomic, strong) NSMutableArray *dataArray3;
@end

@implementation DiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
}


- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

// MARK: ~~~~~~~~ delegate
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return [self.dataArray3 objectAtIndex:section];
            break;
            case 1:
            return [self.dataArray3 objectAtIndex:section];
            break;
        default:
            return @"Unknown";
            break;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray3.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return self.dataArray1.count;
            break;
            case 1:
            return self.dataArray2.count;
            break;
        default:
            return 0;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = self.dataArray1[indexPath.row];
            break;
            case 1:
            cell.textLabel.text = self.dataArray2[indexPath.row];
            break;
        default:
            cell.textLabel.text = @"Unknown";
            break;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

// MARK: ~~~~~~~~ setter
- (NSMutableArray *)dataArray1 {
    if (!_dataArray1) {
        _dataArray1 = [NSMutableArray array];
        [_dataArray1 addObject:@"中国人"];
        [_dataArray1 addObjectsFromArray:@[@"美国",@"英国"]];
    }
    return _dataArray1;;
}

- (NSMutableArray *)dataArray2 {
    if (!_dataArray2) {
        _dataArray2 = [NSMutableArray array];
        [_dataArray2 addObjectsFromArray:@[@"黄种人",@"白种人",@"黑鬼"]];
    }
    return _dataArray2;;
}

- (NSMutableArray *)dataArray3 {
    if (!_dataArray3) {
        _dataArray3 = [NSMutableArray array];
        [_dataArray3 addObjectsFromArray:@[@"种族",@"国家"]];
    }
    return _dataArray3;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
